const UserModel = new (require('../model/User'));
const FilesModel = new (require('../model/Files'));

// 查询
exports.getList = async (req, res) => {
    const { userid } = req.query

    console.log('userid:' + userid);
    res.json({
        status: 1,
        message: '列表',
        data: {
            // count,
            list: 1111,
        }
    });
}

// 删除
exports.deleteDate = async (req, res) => {

    const data = {
        username: '1002'
    };
    // const result = await UserModel.where(data).softDelete();    //软删除
    const result = await UserModel.where(data).forceDelete();    //真实删除

    console.log(result);
    if (result == false) {
        res.json({
            status: 0,
            message: '删除失败' + result,
            data: ''
        })
    }
    res.json({
        status: 1,
        message: '删除成功',
        data: ''
    })

}
// 插入数据
exports.createDate = async (req, res) => {
    const data = {
        username: '1006',
        password: '1006',
        salt: '1006',
        staffname: '1006',
        rankid: 3
    };
    const result = await UserModel.insert(data);

    console.log(result);
    if (result > 0) {
        res.json({
            status: 1,
            message: '新增成功',
            data: ''
        })
    } else {
        res.json({
            status: 0,
            message: '新增失败',
            data: ''
        })
    }
}

// 更新
exports.updateData = async (req, res) => {
    data = {
        username: 'zx1001',
        password: 'zx1001'
    }

    const result = await UserModel.where({ id: 1, username: 'zx1001' }).update(data);

    console.log(result);
    if (result > 0) {
        res.json({
            status: 1,
            message: '更新成功',
            data: ''
        })
    } else {
        res.json({
            status: 0,
            message: '更新失败',
            data: ''
        })
    }

}